package com.example.gty.controller;

import com.example.gty.entity.Admins;
import com.example.gty.service.MailService;
import com.example.gty.service.UsersService;
import com.example.gty.utils.BaseUtil;
import com.example.gty.utils.ResultVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
@Api(tags = "用户信息管理")

public class UsersController {
    @Autowired
    private UsersService usersService;
    @Autowired
    private MailService mailService;

    private static String text;

    @ApiOperation("用户登录接口")
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ResultVo login(String no, String password) {
        System.out.println("登录接口");
        ResultVo resultVo = usersService.login(no, password);
        return resultVo;
    }

    @ApiOperation("修改用户自身信息接口")
    @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
    public ResultVo updateUser(String no, @RequestBody BaseUtil object, String s){
        System.out.println(object);
        System.out.println(no);
        if (s!=null && s.equals(text)){
            ResultVo resultVo = usersService.updateUsers(no, object);
            return resultVo;
        }else {
            return new ResultVo(1001,"error",null);
        }
    }

    @ApiOperation("发送邮箱接口")
    @RequestMapping(value = "/send",method = RequestMethod.GET)
    public ResultVo send(String email){
        //生成验证码
        text =  (int)(Math.random()*10)+""+
                (int)(Math.random()*10)+""+(int)(Math.random()*10)+""
                +(int)(Math.random()*10)+"";
        mailService.sendText(email,text);
        return new ResultVo(1000,null,null);
    }




}
